package com.feiyangedu.sample;

public class Main {
    public static void main(String[] args) throws Exception {
        Thread t1  = new HelloThread("Bob");
        t1.start();
//         线程2
        Thread t2 = new Thread(new Hello2Thread());
        t2.start();


        for (int i=0; i< 3; i++){
            System.out.println("Main");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}

class  HelloThread extends  Thread{
    String name;
    public  HelloThread(String name){
        this.name  = name;
    }
    @Override
    public void run() {
        for (int i=0; i< 3; i++){
            System.out.println("Hello, " +name + "!");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

//实现Runable接口
class  Hello2Thread implements  Runnable{

    @Override
    public void run() {
        for (int i=0; i< 3; i++){
            System.out.println("Hello, " +"Hello2Thread" + "!");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}